const { Sequelize } = require('sequelize')
const initModels = require('./models/init-models') // 假设模型文件在 models 目录下



if (process.env.NODE_ENV === 'production') {
  console.log('prod')
  dbname = 'todo'
  dbuser = 'todo'
  dbpass = 'todo'
  dbhost = 'todo'
} else if (process.env.NODE_ENV === 'development') {
  console.log('dev')
  dbname = '$DBNAME$'
  dbuser = '$DBUSER$'
  dbpass = '$DBPWD$'
  dbhost = '$DBHOST$'
} 


// 创建 Sequelize 实例
const sequelize = new Sequelize(dbname, dbuser, dbpass, {
  host: dbhost,
  dialect: 'mysql'
})

// 定义一个变量来存储单例实例
let singletonModels;

// 定义一个函数来获取单例模型
function getModels() {
  if (!singletonModels) {
    // 初始化模型
    singletonModels = initModels(sequelize);
  }
  return singletonModels;
}

// 导出获取单例模型的函数
module.exports = {
  getModels
};